<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
		<form id="user-form">
			<div class="select-list">
				<ul>
					<li>
						提示：<input id="searchText" type="text" name="searchText" style="width:160px"/>
					</li>
					<li>
						错误代码组：<input type="text" name="errorgroup" style="width:160px"/>
					</li>
					<li>
						错误代码10进制：<input id="codeBase10Search" type="text" name="codeBase10" style="width:160px"/>
					</li>
					<li>
						错误代码62进制：<input id="codeBase62Search" type="text" name="codeBase62" style="width:160px"/>
					</li>
					<li>
						<a class="btn btn-primary btn-rounded btn-sm" onclick="tableSearch()"><i class="fa fa-search"></i>&nbsp;搜索</a>
					</li>
					<li>
						<a class="btn btn-primary btn-rounded btn-sm" onclick="exportJson()"><i class="fa fa-download"></i>&nbsp;导出JSON</a>
					</li>
					<li>
						<a class="btn btn-primary btn-rounded btn-sm" onclick="uploadAliyun()"><i class="fa fa-download"></i>&nbsp;生成JSON上传至阿里云</a>
					</li>

					<li>
						<a class="btn btn-primary btn-rounded btn-sm" onclick="parserBase62()"><i class="fa fa-pinterest"></i>&nbsp;解析62进制</a>
					</li>
					<li>
						<a class="btn btn-primary btn-rounded btn-sm" onclick="clearCache()"><i class="fa fa-remove"></i>&nbsp;清空缓存</a>
					</li>
                    <li>
						<div id="msg_console"></div>
					</li>
				</ul>
			</div>
		</form>
		<div class="btn-group hidden-xs" id="toolbar" role="group">
			<!--<a class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add()" shiro:hasPermission="module:errorcodeCache:add">-->
				<!--<i class="fa fa-plus"></i> 新增-->
			<!--</a>-->
			<!--<a class="btn btn-outline btn-danger btn-rounded" onclick="$.operate.removeAll()" shiro:hasPermission="module:errorcodeCache:remove">-->
				<!--<i class="fa fa-trash-o"></i> 删除-->
			<!--</a>-->
		</div>
			
		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true" style="white-space:nowrap"></table>
		</div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('module:errorcodeCache:edit')}]];
        var removeFlag = [[${@permission.hasPermi('module:errorcodeCache:remove')}]];
        var prefix = ctx + "module/errorcodeCache"

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "错误代码缓存",
                sortable: true,                                     // 是否启用排序
                sortStable: true,                                   // 设置为 true 将获得稳定的排序
                sortName: "updateTime",                                // 排序列名称
                sortOrder: "desc",                              // 排序方式  asc 或者 desc
                search: false,									//不显示table上的搜索框
                columns: [
                    // {
		        //     checkbox: true
		        // },
				// {
				// 	field : 'apiErrorcodeCacheId',
				// 	title : 'ID'
				// },
				{
					field : 'apiErrorcodeId', 
					title : '错误代码ID' 
				},
				{
					field : 'errorgroup', 
					title : '错误代码组' 
				},
				{
					field : 'errorcode', 
					title : '错误代码编号' 
				},
				{
					field : 'codeBase10', 
					title : '错误代码10进制' 
				},
				{
					field : 'codeBase62',
					title : '错误代码62进制'
				},
				{
					field : 'projectTree', 
					title : '项目层级' 
				},
				{
					field : 'description', 
					title : '前端提示' 
				},
				// {
				// 	field : 'createBy',
				// 	title : '创建者'
				// },
				// {
				// 	field : 'createTime',
				// 	title : '创建时间'
				// },
				{
					field : 'updateBy', 
					title : '更新者' 
				},
				{
					field : 'updateTime', 
					title : '更新时间' 
				},
				{
					field : 'remark', 
					title : '备注' 
		        } ]
            };
            $.table.init(options);
        });
        
        function tableSearch() {
            console.log("codeBase10=",$("#codeBase10Search").val());
            if(!$.common.isEmpty($("#codeBase10Search").val()))
			{
			    var codeBase10Temp = $("#codeBase10Search").val();
			   var errorGroup= codeBase10Temp>>12;
                var errorCode= codeBase10Temp&4095;
                console.log("errorGroup=",errorGroup);
                console.log("errorCode=",errorCode);
                $("#msg_console").text("错误组="+errorGroup+",错误码="+errorCode);
			}else{
                $("#msg_console").text("");
			}
			$.table.search();
        }

		// 生成代码上传阿里云
		function uploadAliyun() {
			$.modal.confirm("确定要生成json后上传到阿里云吗?", function() {
				layer.msg('执行成功,正在生成代码并上传,请稍后…', { icon: 1 });
				var config = {
					url:  prefix+"/uploadAliyun/json",
					type: "post",
					success: function(result) {
						if (result.code == web_status.SUCCESS) {
							$.modal.alertSuccess(result.msg);
						} else {
							$.modal.alertError(result.msg);
						}
					}
				};
				$.ajax(config);
			})
		}

        // 生成代码
        function exportJson() {
            $.modal.confirm("确定要生成json代码吗?", function() {
                location.href = prefix + "/export/json";
                layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
            })
        }

        function clearCache() {
			$.modal.confirm("确定要清空缓存吗?", function() {
				var config = {
					url:  prefix + "/clear",
					type: "post",
					dataType: "text",
					success: function(result) {
						console.log(result);
						var msg="缓存已清除,总共"+result+ "行";
						$("#msg_console").text(msg);
						layer.msg(msg, { icon: 1 });
					}
				};
				$.ajax(config);
			})
		}

        function parserBase62() {
			var codeBase10Temp = $("#codeBase62Search").val();
			console.log("codeBase10Temp=",codeBase10Temp);
			var postData={
				base62:codeBase10Temp
			};
			var config = {
				// url:  "/module/errorcodeCache/parserBase62?base62="+codeBase10Temp,
				url:  "/module/errorcodeCache/parserBase62",
				type: "post",
				dataType: "text",
				data: postData,
				success: function(result) {

				    console.log(result);
					console.log("refresh--------")
					var errorGroup= result>>12;
					var errorCode= result&4095;
					console.log("errorGroup=",errorGroup);
					console.log("errorCode=",errorCode);
					$("#msg_console").text("错误组="+errorGroup+",错误码="+errorCode);
				}
			};
			$.ajax(config);

		}

    </script>
</body>
</html>